package com.amuji.adiaosexpense.db;

import com.amuji.adiaosexpense.util.Constants;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.util.Log;

public class PersonSQLiteHelper extends SQLiteOpenHelper {
  public static final String TABLE_PERSONS = "persons";
  public static final String COLUMN_ID = "_id";
  public static final String COLUMN_FIRST_NAME = "first_name";
  public static final String COLUMN_LAST_NAME = "last_name";

  
  // Database creation sql statement
  private static final String DATABASE_CREATE = "create table "
      + TABLE_PERSONS 
      + "(" + COLUMN_ID + " integer primary key autoincrement, "
      + COLUMN_FIRST_NAME + " text not null, "
      + COLUMN_LAST_NAME + " text not null);";

  public PersonSQLiteHelper(Context context) {
    super(context, Constants.DATABASE_NAME, null, Constants.DATABASE_VERSION);
  }
  
  @Override
  public void onCreate(SQLiteDatabase database) {
    database.execSQL(DATABASE_CREATE);
  }

  @Override
  public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
    Log.w(PersonSQLiteHelper.class.getName(),
        "Upgrading database from version " + oldVersion + " to "
            + newVersion + ", which will destroy all old data");
    db.execSQL("DROP TABLE IF EXISTS " + TABLE_PERSONS);
    onCreate(db);
  }

}
